package cn.hzking.gjmall.adpters.home;

import android.app.Activity;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.hzking.gjmall.R;
import cn.hzking.gjmall.app.Gjmall;
import cn.hzking.gjmall.bean.HomeDataBean;
import cn.hzking.gjmall.utils.UriMatch;
import cn.hzking.gjmall.view.DashView;

/**主页头部各个品牌馆的分类
 * Created by Administrator on 2018/2/7.
 */

public class SubareaAdpter extends BaseQuickAdapter<HomeDataBean.DataBean.SubareaBean,BaseViewHolder> {
    public SubareaAdpter(int layoutResId, @Nullable List<HomeDataBean.DataBean.SubareaBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder baseViewHolder, final HomeDataBean.DataBean.SubareaBean subareaBean) {
        ImageView view = baseViewHolder.getView(R.id.subarea_iamge);
        TextView textName = baseViewHolder.getView(R.id.subarea_title);
        TextView textDec = baseViewHolder.getView(R.id.subarea_detail);
        DashView dashViewButtom = baseViewHolder.getView(R.id.subar_buttom_line);
        DashView dashViewRight = baseViewHolder.getView(R.id.subar_right_line);
        textDec.setText(subareaBean.getDesc());
        textName.setText(subareaBean.getName());
        Glide.with(mContext).load(Gjmall.getOssHost()+subareaBean.getImage()).into(view);
        baseViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //todo 五六块的点击事件
                new UriMatch((Activity) mContext,subareaBean.getUrl()).match();
                //UIUtils.showToast(mContext,"subra"+baseViewHolder.getLayoutPosition(), Toast.LENGTH_SHORT);
            }
        });
        if(getItemCount() == 5){//五个的布局
            if(baseViewHolder.getLayoutPosition() == 1 || baseViewHolder.getLayoutPosition() == 4){
                dashViewRight.setVisibility(View.GONE);
            }else {
                dashViewRight.setVisibility(View.VISIBLE);
            }
            if(baseViewHolder.getLayoutPosition() >=2){
                dashViewButtom.setVisibility(View.GONE);
            }else {
                dashViewButtom.setVisibility(View.VISIBLE);
            }
        }else if(getItemCount() == 6){//六个的布局
            if(baseViewHolder.getLayoutPosition() == 2 || baseViewHolder.getLayoutPosition() == 5){
                dashViewRight.setVisibility(View.GONE);
            }else {
                dashViewRight.setVisibility(View.VISIBLE);
            }
            if(baseViewHolder.getLayoutPosition() >2){
                dashViewButtom.setVisibility(View.GONE);
            }else {
                dashViewButtom.setVisibility(View.VISIBLE);
            }
        }
    }
}
